package com.pzhu.service.impl;

import com.pzhu.dao.LoginDao;
import com.pzhu.dao.impl.LoginDaoImpl;
import com.pzhu.pojo.User;
import com.pzhu.service.LoginService;

public class LoginServiceImpl implements LoginService {


    //    public void test(){
//        checkUser("张三","111");
//    }
//    添加Dao层成员变量
    private final LoginDao loginDao = new LoginDaoImpl();
    public boolean checkUser(String uname, String pwd) {
//      封装数据
        User userInPut = new User(uname, pwd);
//      调用Dao层查询数据
        User userSelect = loginDao.checkUser(userInPut);
//      判断数据是否匹配 如果没有数据，则直接跳过匹配
        if (userSelect != null) {
//            equals密码判断
            return userInPut.getPwd().equals(userSelect.getPwd());
        }
        return false;
    }

    @Override
    public boolean checkUserById(int userId) {
        User userInPut = new User(userId);
        User userSelect = loginDao.checkUserById(userInPut);
        return userSelect.getUid()==userId;
    }



    @Override
    public String selectUNameByUId(int userId) {
        return loginDao.selectUNameByUid(userId);
    }

    @Override
    public User selectUserById(int id) {
        User userInPut = new User(id);
        return loginDao.selectUserById(userInPut);
    }

    @Override
    public int selectUidByUName(String uname) {
        return loginDao.selectUidByUName(uname);
    }
}
